package com.jirong.shop.controller;

import com.jirong.shop.service.TUserService;
import com.jirong.shop.vo.LoginVo;
import com.jirong.shop.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
//@Slf4j
public class LoginController {
    @Autowired
    TUserService userService;

    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    /**
     * 登录功能
     *
     * @param loginVo
     * @return
     */
    @RequestMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) {
//        log.info("{}", loginVo);
//        从数据库查询进行比较
        RespBean respBean = userService.doLogin(loginVo,request,response);
//        System.out.println(respBean);
        return respBean;
    }
}
